package com.fxd.crm.web.controller.teach;

import com.fxd.crm.model.CourseOrder;
import com.fxd.crm.model.PageResult;
import com.fxd.crm.model.curdResult;
import com.fxd.crm.model.teach;
import com.fxd.crm.service.ICourseOrderService;
import com.fxd.crm.service.ITeachService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @auther fuxudong
 * @date 2021/4/5 - 11:18
 */
@RestController
@RequestMapping("/teach")
public class teachBodyController {
    @Autowired
    ITeachService teachService;

    /**
     * page:显示当前页
     * limit：每次显示多少条
     *
     * @return
     */
    @RequestMapping("listjson")
    public PageResult<teach> listJson(teach teach, int page, int limit) {
        PageResult<teach> pageResult = teachService.findPageResult(teach, page, limit);
        return pageResult;
    }

    @RequestMapping("save")
    public curdResult save(teach teach) {
        curdResult curdResult;
        if (teach.getTeach_id() != null) {
            curdResult = new curdResult(1, "成功");
            teachService.update(teach);
        } else {
            curdResult = new curdResult(1, "成功");
            teachService.save(teach);
        }
        return curdResult;
    }

    @RequestMapping("delete")
    public curdResult delete(Integer teach_id) {
        curdResult curdResult = new curdResult();
        teachService.deleteByOrderId(teach_id);
        return curdResult;

    }
}
